package com.app.mymvp.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.app.mymvp.entity.HomeImageEntity;

import java.util.List;

/**
 * Created by hj on 2015/10/27.
 * 广告轮播图适配器
 */
public class AdPagerAdapter extends PagerAdapter {
    /** 上下文 */
    private Context context;
    /** 数据集合 */
    private List<HomeImageEntity> list;
    /**引导界面的集合*/
    private List<View> views = null;
    private int selectIndex;
    public AdPagerAdapter(Context context, List<HomeImageEntity> list, List<View> views) {
        this.context = context;
        this.list = list;
        this.views = views;
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
    }

    /**
     * 界面的数量
     */
    public int getCount() {
        // 判断当前的界面是否为空
        if (views != null) {
            return views.size();
        }
        return 0;
    }

    /**
     * 该界面是否由当前的对象进行创建
     */
    public boolean isViewFromObject(View arg0, Object arg1) {
        return (arg0 == arg1);
    }

    /**
     * 销毁界面
     */
    public void destroyItem(View container, int position, Object object) {
        ((ViewPager) container).removeView(views.get(position));
    }

    /**
     * 装载界面
     */
    public Object instantiateItem(View container, int position) {
        ((ViewPager) container).addView(views.get(position), 0);
        container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        return views.get(position);
    }

}